/**
 * @author Tobias Boehm
 *
 * 06.06.2011
 */
package org.anddev.andengine.extension.tbsengine.match;

import java.io.IOException;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.layer.tiled.tmx.util.exception.TMXLoadException;
import org.anddev.andengine.extension.tbsengine.map.AbsMap;
import org.anddev.andengine.extension.tbsengine.match.gamestate.AbsClientGlobalGameState;
import org.anddev.andengine.extension.tbsengine.match.gamestate.AbsPlayerGameState;
import org.anddev.andengine.extension.tbsengine.message.server.ingame.AbsServerMatchReconnectRequestReplyMessage;
import org.xml.sax.SAXException;

import android.content.Context;

/**
 * This is the abstract implementation of the client side version of 
 * {@link AbsMatch}. You may implement this class on your game client.
 * 
 * 
 * @author Tobias Boehm
 *
 * @param <PlayerGameStateClass> - Your implementation of {@link AbsPlayerGameState}
 * @param <ClientGlobalGameStateClass> - Your implementation of {@link AbsClientGlobalGameState}
 * @param <MapClass> - Your implementation of {@link AbsMap}
 * @param <ServerMatchReconnectRequestReplyMessageClass> - Your implementation of the {@link AbsServerMatchReconnectRequestReplyMessage} object.
 */
public abstract class AbsClientMatch<PlayerGameStateClass extends AbsPlayerGameState,
									 ClientGlobalGameStateClass extends AbsClientGlobalGameState,
									 MapClass extends AbsMap,
									 ServerMatchReconnectRequestReplyMessageClass extends AbsServerMatchReconnectRequestReplyMessage>

							extends AbsMatch<PlayerGameStateClass,ClientGlobalGameStateClass,MapClass> {

	/**
	 * A reference to the server message which contains all necessary
	 * information to create a ClientMatch instance.
	 */
	protected final ServerMatchReconnectRequestReplyMessageClass mMessage;
	
	
	/**
	 * The default constructor of this class. All necessary information to
	 * create a ClientMatch instance are stored in the pMessage object.
	 * 
	 * @param pContext
	 * @param pEngine - A reference to the game engine.
	 * @param pMessage - A reference to the server message which contains all necessary information to create a ClientMatch instance.
	 * 
	 * @throws IOException This exception is thrown if {@link #loadMap(String, Context, Engine)} is unable to load the map file.
	 * @throws SAXException This exception is thrown if {@link #loadMap(String, Context, Engine)} is unable to parse the map file.
	 * @throws TMXLoadException This exception is thrown if {@link #loadMap(String, Context, Engine)} discovers a problem with the map file format.
	 */
	public AbsClientMatch(final Context pContext, final Engine pEngine, final ServerMatchReconnectRequestReplyMessageClass pMessage) throws IOException, SAXException, TMXLoadException {
		super(pContext, pEngine, pMessage.getMatchID(), pMessage.getMapID());
		
		this.mMessage = pMessage;
		
		this.initMatch();
	}
	

	@Override
	protected ClientGlobalGameStateClass createGlobalGameState() {
		
		return this.createGlobalClientGameState(this.mMessage);
	}
	
	/**
	 * This method should return an instance of your implementation of 
	 * {@link AbsClientGlobalGameState}. This method provides a server message
	 * as a parameter which contains all necessary information to create a
	 * client global game state.
	 * 
	 * @param pMessage - A reference to the server message which contains all necessary information to create a ClientMatch instance.
	 * 
	 * @return An instance of your implementation of {@link AbsClientGlobalGameState}.
	 */
	protected abstract ClientGlobalGameStateClass createGlobalClientGameState(final ServerMatchReconnectRequestReplyMessageClass pMessage);
	
	@Override
	public void completeMatch() {
		// TODO Auto-generated method stub
		
	}
}
